import os
#from langchain.chat_models import ChatDashScope
from langchain.llms import Tongyi
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain


llm = Tongyi()

text_contents = """
    1. 苹果公司是一家全球知名的科技公司，总部位于加利福尼亚州的苹果园。
    2. 苹果公司的主要产品包括iPhone、iPad、Mac电脑、Apple Watch等。
    """
def ask(content):
    
    fact_template = PromptTemplate(
        input_variables=["text_input"],
        template=("Extract the key facts out of this text. "
                "Don't include opinions. Give each fact a number "
                "and keep them short sentences. :\n\n {text_input}")
    )

    fact_extraction_chain = LLMChain(
        llm=llm, prompt=fact_template)

    facts = fact_extraction_chain.run(text_contents)

    print(facts)

    role_template = PromptTemplate(
        input_variables=["facts"],
        template=("You are a data analyst. Take the following list of facts "
                "and use them to write a short paragrah for investors. "
                "Don't leave out key info:\n\n {facts}")
    )

    data_analysis_chain = LLMChain(llm=llm, prompt=role_template)

    data_analysis_facts = data_analysis_chain.run(facts)

    print(data_analysis_facts)

    knowledge_template = PromptTemplate(
        input_variables=["facts"],
        template=("Take the following list of facts and turn them "
                "into triples for a knowledge graph:\n\n {facts}")
    )

    knowledge_chain = LLMChain(llm=llm, prompt=knowledge_template)

    knowledge_graph = knowledge_chain.run(facts)
    return knowledge_graph

#knowledge_graph=ask(text_contents) 
 